<?php // $Header: /cvsroot/tsheet/timesheet.php/edit.php,v 1.9 2005/02/03 08:06:10 vexil Exp $
// Authenticate
require("class.AuthenticationManager.php");
require("class.CommandMenu.php");
if (!$authenticationManager->isLoggedIn()) {
	Header("Location: login.php?redirect=$_SERVER[PHP_SELF]");
	exit;
}

// Connect to database.
$dbh         = dbConnect();
$contextUser = strtolower($_SESSION['contextUser']);

//load local vars from superglobals
$save_changes = isset($_REQUEST['save_changes']) ? $_REQUEST['save_changes']: false;
$task_id      = $_REQUEST['task_id'];
$proj_id      = $_REQUEST['proj_id'];
$client_id    = $_REQUEST['client_id'];
$trans_num    = $_REQUEST['trans_num'];
$month        = $_REQUEST['month'];
$day          = $_REQUEST['day'];
$year         = $_REQUEST['year'];
$action       = isset($_REQUEST["action"]) ? $_REQUEST["action"]: "edit";

if ($action == "saveChanges") {
	$clock_on_date_year   = $_REQUEST['clock_on_date_year'];
	$clock_on_date_month  = $_REQUEST['clock_on_date_month'];
	$clock_on_date_day    = $_REQUEST['clock_on_date_day'];
	$clock_off_date_year  = $_REQUEST['clock_off_date_year'];
	$clock_off_date_month = $_REQUEST['clock_off_date_month'];
	$clock_off_date_day   = $_REQUEST['clock_off_date_day'];
	$clock_on_time_hour   = $_REQUEST['clock_on_time_hour'];
	$clock_on_time_min    = $_REQUEST['clock_on_time_min'];
	$clock_off_time_hour  = $_REQUEST['clock_off_time_hour'];
	$clock_off_time_min   = $_REQUEST['clock_off_time_min'];
	$dayInput             = $_REQUEST['dayInput']; 
	$log_message          = $_REQUEST['log_message'];
	
	/*
	
    $clock_on_time_hour = 0;
	if ($dayInput == 0.25) 
	{
	    $clock_off_time_hour = 2;
	}
	if ($dayInput == 0.5) 
	{
	    $clock_off_time_hour  = 4;

	}
	if ($dayInput == 0.75) 
	{
	    $clock_off_time_hour  = 6;

	}
	if ($dayInput == 0.5) 
	{
	    $clock_off_time_hour  = 8;

	}	
	*/
	
	
	
	$clock_on_time_string = "$clock_on_date_year-$clock_on_date_month-$clock_on_date_day $clock_on_time_hour:$clock_on_time_min:00";
	$clock_off_time_string = "$clock_off_date_year-$clock_off_date_month-$clock_off_date_day $clock_off_time_hour:$clock_off_time_min:00";

	$queryString = "UPDATE $TIMES_TABLE SET start_time='$clock_on_time_string', ".
								"end_time='$clock_off_time_string', ".
								"log_message='$log_message', ".
								"task_id='$task_id', " .
								"proj_id='$proj_id' " .
								"WHERE ".
								"trans_num='$trans_num'";

	list($qh,$num) = dbQuery($queryString);

	Header("Location: daily.php?proj_id=$proj_id&task_id=$task_id&month=$month&year=$year&day=$day");
	exit;
}

//define the command menu
include("timesheet_menu.inc");

//get trans info
$trans_info = get_trans_info($trans_num);

		//Due to a bug in mysql with converting to unix timestamp from the string, 
		//we are going to use php's strtotime to make the timestamp from the string.
		//the problem has something to do with timezones.
		$trans_info["start_time"] = strtotime($trans_info["start_time_str"]);
		$trans_info["end_time"] = strtotime($trans_info["end_time_str"]);

if ($action != "saveChanges") {
	$proj_id = $trans_info["proj_id"];
	$task_id = $trans_info["task_id"];
	$client_id = $trans_info["client_id"];
}

include("form_input.inc");

?>
<html>
    <head>
        <title>Edit Work Log Record for <?php echo $contextUser; ?></title>
        <?php 
        include("header.inc");
        include("client_proj_task_javascript.inc");
        ?>
    </HEAD>
    <BODY <?php include ("body.inc"); ?> onload="doOnLoad();">
        <?php include ("banner.inc"); ?>
        <table width="500" align="center" border="0" cellspacing="0" cellpadding="0">
        	<tr>
        		<td width="100%" class="face_padding_cell">
        			<table width="100%" border="0" class="table_head">
        				<tr>
        					<td align="left" nowrap class="outer_table_heading" nowrap>
        						Edit Work Log Record:
        					</td>
        				</tr>
        			</table> 
                    <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="outer_table">
                    
        	        	<form name="editForm" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" id="theForm">
        	        	<input type="hidden" name="year"      value="<?php echo $year; ?>">
        	        	<input type="hidden" name="month"     value="<?php echo $month; ?>">
        	        	<input type="hidden" name="day"       value="<?php echo $day; ?>">
        	        	<input type="hidden" id="client_id"   value="<?php echo $client_id; ?>" name="client_id">
        	        	<input type="hidden" id="proj_id"     value="<?php echo $proj_id; ?>"   name="proj_id">
        	        	<input type="hidden" id="task_id"     value="<?php echo $task_id; ?>"   name="task_id">																										
        	        	<input type="hidden" name="trans_num" value="<?php echo $trans_num; ?>">
        	        	<input type="hidden" name="action"    value="saveChanges" />
        	        	
        	        	<tr>
        	        		<td>			
        	        			<table width="100%" border="0" cellpadding="1" cellspacing="2" class="table_body">				
        	        				<tr>
        	        					<td align="left">
        	        						<table width="100%" border="0">
        	        							<tr>
        	        								<td align="left" width="100%" nowrap>
        	        										<table width="100%" border="0" cellspacing="0" cellpadding="0">
        	        											<tr>
        	        												<td><table width="50"><tr><td>Client:</td></tr></table></td>
        	        												<td width="100%">
        	        													<select id="clientSelect" name="clientSelect" onChange="onChangeClientSelect();" style="width: 100%;" />
        	        												</td>
        	        											</tr>
        	        										</table>											
        	        								</td>									
        	        							</tr>																									
        	        							<tr>
        	        								<td align="left" width="100%" nowrap>
        	        										<table width="100%" border="0" cellspacing="0" cellpadding="0">
        	        											<tr>
        	        												<td><table width="50"><tr><td>Project:</td></tr></table></td>
        	        												<td width="100%">
        	        													<select id="projectSelect" name="projectSelect" onChange="onChangeProjectSelect();" style="width: 100%;" />
        	        												</td>
        	        											</tr>
        	        										</table>
        	        								</td>									
        	        							</tr>																		
        	        							<tr>
        	        								<td align="left" width="100%">
        	        										<table width="100%" border="0" cellspacing="0" cellpadding="0">
        	        											<tr>
        	        												<td><table width="50"><tr><td>Task:</td></tr></table></td>
        	        												<td width="100%">
        	        													<select id="taskSelect" name="taskSelect" onChange="onChangeTaskSelect();" style="width: 100%;" />
        	        												</td>
        	        											</tr>
        	        										</table>
        	        								</td>									
        	        							</tr>																										
        	        						</table>
        	        					</td>
        	        				</tr>
        	        				<tr>
        	        					<td align="center">
        	        						<table>			
        	        							<tr>
        	        								<td>
        	        									<table align="center" class="clock_on_box" >											
        	        										<tr>
                                    	            	    	<td>
                                    	            	    		<img src="images/clock-green-sml.gif" border="0">
                                    	            	    	</td>
                                                                <td align="left" class="clock_on_text">
                                    	            	    		Time available for this task: 
                                    	            	    	</td>																			
                                    	            	    	<td valign="middle">
        	        											    <?php $duration = (date("G", $trans_info["end_time"]) - date("G", $trans_info["start_time"])) / 8; ?>
                        	        								<select name="dayInput" id="dayInput" size="1">
                                                                        <?php if ($duration == 0.25) { ?>
        	        														      <option selected value=""> <?php echo $duration ?>
        	        												    <?php } else { ?>
        	        													          <option>0.25</option> 
        	        													<?php }
        	        														  if ($duration == 0.5) { ?>
        	        														      <option selected value=""> <?php echo $duration ?>
        	        													<?php } else { ?>
        	        													          <option>0.5</option> 
        	        													<?php } 
        	        														  if ($duration == 0.75) { ?>
        	        														      <option selected value=""> <?php echo $duration ?>
        	        													<?php } else { ?>
        	        													          <option>0.75</option> 
        	        													<?php } 
        	        														  if ($duration = 1) { ?>
        	        														      <option selected value=""> <?php echo $duration ?>
        	        													<?php } else { ?>
        	        													          <option>1</option> 
        	        													<?php } ?>
                                                                        
                                                                    </select>
                                    	            	    	</td>
                        	        							
                        	        							<td align="left" class="clock_on_text">
                                    	            	    		day
                                    	            	    	</td>
                                    	            	    </tr>			
        	        									</table>
        	        								</td>
        	        							</tr>
        	        							<tr>
        	        								<td colspan="3">
        	        									Log Message:
        	        								</td>
        	        							</tr>
        	        							<tr>
        	        								<td colspan="3" align="center">
        	        									<textarea name="log_message" cols="60" rows="5" style="width: 100%;"><?php echo trim(stripslashes($trans_info["log_message"])); ?></textarea>
        	        								</td>
        	        							</tr>	
        	        							<tr>
        	        								<td>
        	        									<table width="100%" border="0" class="table_bottom_panel">
        	        										<tr>
        	        											<td align="center">
        	        												<input type="button" value="Save Changes" name="submitButton" id="submitButton" onClick="onSubmit();">
        	        											</td>
        	        									</tr>
        	        									</table>
        	        								</td>
        	        							</tr>																						
        	        						</table>
        	        					</td>
        	        				</tr>
        	        			</table>
        	        		</td>
        	        	</tr>
        	        	</form>		
        	        </table>	
        
        		</td>
        	</tr>
        </table>
        	
        
        <?php include ("footer.inc"); ?>
    </body>
</html>
